package com.jiayinlending.jiayindai.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiayinlending.jiayindai.R;
import com.jiayinlending.jiayindai.activity.myrepay.RepaymentRecordActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by xiaohei on 2017/3/28.
 */

public class RepayFragment extends Fragment {
    @Bind(R.id.toolbar_subtitle)
    TextView toolbarSubtitle;
    @Bind(R.id.toolbar_title)
    TextView toolbarTitle;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    private View mRootView;//缓存Fragment view
    private RecyclerView recyler;

    @Nullable
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (mRootView != null) {
            return mRootView;
        } else {
            mRootView = inflater.inflate(R.layout.fragment_repay, container, false);
//            //缓存的mRootView需要判断是否已经被加过parent， 如果有parent需要从parent删除，要不然会发生这个mRootView已经有parent的错误。
//            ViewGroup parent = (ViewGroup) mRootView.getParent();
//            if (parent != null) {
//                parent.removeView(mRootView);
//            }
//            ArrayList<Info> list = new ArrayList<>();
//            for (int i = 0; i < 10; i++) {
//                list.add(new Info());
//            }
//            LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
//            recyler = ((RecyclerView) mRootView.findViewById(R.id.recycler));
//            //自动测量
//            layoutManager.setAutoMeasureEnabled(true);
//            //禁用滑动
//            recyler.setNestedScrollingEnabled(false);
//            recyler.setLayoutManager(layoutManager);
//            layoutManager.setOrientation(OrientationHelper.VERTICAL);
//            recyler.setAdapter(new HomeRecylerAdpater(getContext(), list));
            initTitleView();
            return mRootView;
        }
    }

    private void initTitleView() {
        TextView toolbar_title  = (TextView) mRootView.findViewById(R.id.toolbar_title);
        TextView toolbar_subtitle = (TextView) mRootView.findViewById(R.id.toolbar_subtitle);
        toolbar_title.setText("我的还款");
        toolbar_subtitle.setText("还款记录");
        toolbar_subtitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), RepaymentRecordActivity.class));
            }
        });

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
